import Vue from "vue";
import Router from "vue-router";
import store from "../vuex/store";
import { LoadingBar } from "view-design";


Vue.use(Router);

// const routes = [
//   {
//     path: "/",
//     name: "signin",
//     meta: {
//       title: "文旅绿码"
//     },
//     component: resolve => require(["../page/signin.vue"], resolve)
//   },
//   {
//     path: "/warning",
//     name: "404",
//     meta: {
//       title: "出错了"
//     },
//     component: resolve => require(["../page/404.vue"], resolve)
//   },

//   {
//     path: "/wechat",
//     name: "微信扫码登录",
//     meta: {
//       title: "微信扫码登录"
//     },
//     component: resolve => require(["../page/wechat.vue"], resolve)
//   },
//   {
//     path: "/wechatRouter",
//     name: "跳转微信",
//     meta: {
//       title: "跳转微信"
//     },
//     component: resolve => require(["../page/routerWechat.vue"], resolve)
//   },
//   {
//     path: "/helpText",
//     name: "帮助文档",
//     meta: {
//       title: "帮助文档"
//     },
//     component: resolve => require(["../page/helpText.vue"], resolve)
//   },
//   {
//     path: "/helpTextLook",
//     name: "帮助文档查看",
//     meta: {
//       title: "帮助文档查看"
//     },
//     component: resolve => require(["../page/helpTextLook.vue"], resolve)
//   },
//   {
//     path: "/freeApplication",
//     name: "免费申请",
//     meta: {
//       title: "免费申请"
//     },
//     component: resolve => require(["../page/free.vue"], resolve)
//   },
//   {
//     path: "/webview",
//     name: "webview",
//     meta: {
//       title: "拱墅博物通"
//     },
//     component: resolve => require(["../page/webview.vue"], resolve)
//   },
//   {
//     path: "/achievements",
//     name: "achievements",
//     meta: {
//       title: "员工绩效"
//     },
//     component: resolve => require(["../page/other/achievements.vue"], resolve)
//   },
//   {
//     path: "/main",
//     name: "main",
//     component: resolve => require(["../page/main.vue"], resolve),
//     children: [
//       {
//         path: "/mseumManagement",
//         name: "博物馆管理",
//         meta: {
//           title: "博物馆管理"
//         },
//         component: resolve => require(["../page/mseumManagement.vue"], resolve)
//       },
//       {
//         path: "/exhibitionHall",
//         name: "层级管理",
//         meta: {
//           title: "层级管理"
//         },
//         component: resolve =>
//           require(["../page/guide/exhibitionHall.vue"], resolve)
//       },
//       {
//         path: "/numberExhibition",
//         name: "数字展览",
//         meta: {
//           title: "数字展览"
//         },
//         component: resolve =>
//           require(["../page/guide/numberExhibition.vue"], resolve)
//       },
//       {
//         path: "/museumTool",
//         name: "场馆管理",
//         meta: {
//           title: "场馆管理"
//         },
//         component: resolve => require(["../page/mseumManagement.vue"], resolve)
//       },
//       {
//         path: "/exhibits",
//         name: "展品管理",
//         meta: {
//           title: "展品管理"
//         },
//         component: resolve => require(["../page/guide/exhibits.vue"], resolve)
//       },
//       {
//         path: "/roleList",
//         name: "角色列表",
//         meta: {
//           title: "角色列表"
//         },
//         component: resolve => require(["../page/role/role.vue"], resolve)
//       },
//       {
//         path: "/setUser",
//         name: "系统用户",
//         meta: {
//           title: "系统用户"
//         },
//         component: resolve => require(["../page/role/user.vue"], resolve)
//       },
//       {
//         path: "/recordingReview",
//         name: "录音审核",
//         meta: {
//           title: "录音审核"
//         },
//         component: resolve => require(["../page/recordingReview.vue"], resolve)
//       },
//       {
//         path: "/account",
//         name: "账号管理",
//         meta: {
//           title: "账号管理"
//         },
//         component: resolve => require(["../page/account.vue"], resolve)
//       },
//       {
//         path: "/zixunList",
//         name: "资讯列表",
//         meta: {
//           title: "资讯列表"
//         },
//         component: resolve => require(["../page/zixun/zixunList.vue"], resolve)
//       },
//       {
//         path: "/channelManagement",
//         name: "资讯类别管理",
//         meta: {
//           title: "资讯类别管理"
//         },
//         component: resolve =>
//           require(["../page/channel/channelManagement.vue"], resolve)
//       },
//       {
//         path: "/checkChannel",
//         name: "查看频道",
//         meta: {
//           title: "查看频道"
//         },
//         component: resolve =>
//           require(["../page/channel/checkChannel.vue"], resolve)
//       },

//       {
//         path: "/dataCrawler",
//         name: "数据爬虫",
//         meta: {
//           title: "数据爬虫"
//         },
//         component: resolve =>
//           require(["../page/zixun/dataCrawler.vue"], resolve)
//       },
//       {
//         path: "/informationEdit",
//         name: "编辑详情页",
//         meta: {
//           title: "编辑详情页"
//         },
//         component: resolve =>
//           require(["../page/zixun/informationEdit.vue"], resolve)
//       },
//       {
//         path: "/crawlerInformation",
//         name: "爬虫资讯库",
//         meta: {
//           title: "爬虫资讯库"
//         },
//         component: resolve =>
//           require(["../page/zixun/crawlerInformation.vue"], resolve)
//       },
//       {
//         path: "/portrait",
//         name: "用户画像",
//         meta: {
//           title: "用户画像"
//         },
//         component: resolve => require(["../page/portrait.vue"], resolve)
//       },
//       {
//         path: "/Visit",
//         name: "访问分析",
//         meta: {
//           title: "访问分析"
//         },
//         component: resolve => require(["../page/Visit.vue"], resolve)
//       },
//       {
//         path: "/infor",
//         name: "场馆信息",
//         meta: {
//           title: "场馆信息"
//         },
//         component: resolve => require(["../page/infor.vue"], resolve)
//       },
//       // 紫檀
//       {
//         path: "/appointRule",
//         name: "预约规则",
//         meta: {
//           title: "预约规则"
//         },
//         component: resolve =>
//           require(["../page/appoint/appointRule.vue"], resolve)
//       },
//       {
//         path: "/appointment",
//         name: "团队预约规则",
//         meta: {
//           title: "团队预约规则"
//         },
//         component: resolve =>
//           require(["../page/appoint/appointment.vue"], resolve)
//       },
//       // 紫檀
//       {
//         path: "/user",
//         name: "预约列表",
//         meta: {
//           title: "预约列表"
//         },
//         component: resolve =>
//           require(["../page/appoint/appointList.vue"], resolve)
//       },
//       // 紫檀
//       {
//         path: "/appointUtils",
//         name: "预约配置",
//         meta: {
//           title: "预约配置"
//         },
//         component: resolve =>
//           require(["../page/appoint/appointUtils.vue"], resolve)
//       },
//       {
//         path: "/list",
//         name: "馆区配置",
//         meta: {
//           title: "馆区配置"
//         },
//         component: resolve => require(["../page/list.vue"], resolve)
//       },
//       {
//         path: "/dataStatistics",
//         name: "预约实时数据",
//         meta: {
//           title: "预约实时数据"
//         },
//         component: resolve =>
//           require(["../page/appoint/dataStatistics.vue"], resolve)
//       },
//       {
//         path: "/analysis",
//         name: "游客分析",
//         meta: {
//           title: "游客分析"
//         },
//         component: resolve => require(["../page/appoint/analysis.vue"], resolve)
//       },
//       {
//         path: "/useProtocol",
//         name: "使用协议列表",
//         meta: {
//           title: "使用协议列表"
//         },
//         component: resolve => require(["../page/useProtocol.vue"], resolve)
//       },
//       {
//         path: "/message",
//         name: "通知管理",
//         meta: {
//           title: "通知管理"
//         },
//         component: resolve => require(["../page/message.vue"], resolve)
//       },
//       {
//         path: "/exhibits",
//         name: "用户分析",
//         meta: {
//           title: "用户分析"
//         },
//         component: resolve => require(["../page/user.vue"], resolve)
//       },
//       {
//         path: "/banner",
//         name: "banner管理",
//         meta: {
//           title: "banner管理"
//         },
//         component: resolve => require(["../page/banner.vue"], resolve)
//       },
//       {
//         path: "/liuyan",
//         name: "留言管理",
//         meta: {
//           title: "留言管理"
//         },
//         component: resolve => require(["../page/liuyan.vue"], resolve)
//       },
//       {
//         path: "/integral",
//         name: "积分管理",
//         meta: {
//           title: "积分管理"
//         },
//         component: resolve => require(["../page/integral.vue"], resolve)
//       },
//       {
//         path: "/meituan",
//         name: "美团门票",
//         meta: {
//           title: "美团门票"
//         },
//         component: resolve => require(["../page/ota/meituan.vue"], resolve)
//       },
//       {
//         path: "/tongcheng",
//         name: "同程门票",
//         meta: {
//           title: "同程门票"
//         },
//         component: resolve => require(["../page/ota/tongcheng.vue"], resolve)
//       },
//       {
//         path: "/feizhu",
//         name: "飞猪门票",
//         meta: {
//           title: "飞猪门票"
//         },
//         component: resolve => require(["../page/ota/feizhu.vue"], resolve)
//       },
//       {
//         path: "/xiecheng",
//         name: "携程门票",
//         meta: {
//           title: "携程门票"
//         },
//         component: resolve => require(["../page/ota/xiecheng.vue"], resolve)
//       },
//       {
//         path: "/pinglun",
//         name: "展品评论管理",
//         meta: {
//           title: "展品评论管理"
//         },
//         component: resolve => require(["../page/guide/pinglun.vue"], resolve)
//       },
//       {
//         path: "/data2",
//         name: "轨迹监控报表",
//         meta: {
//           title: "轨迹监控报表"
//         },
//         component: resolve => require(["../page/data/data2.vue"], resolve)
//       },
//       {
//         path: "/data1",
//         name: "访问概览",
//         meta: {
//           title: "访问概览"
//         },
//         component: resolve => require(["../page/data/data1.vue"], resolve)
//       },
//       {
//         path: "/data3",
//         name: "展品监控报表",
//         meta: {
//           title: "展品监控报表"
//         },
//         component: resolve => require(["../page/data/data3.vue"], resolve)
//       },
//       {
//         path: "/data4",
//         name: "访问监控报表",
//         meta: {
//           title: "访问监控报表"
//         },
//         component: resolve => require(["../page/data/data4.vue"], resolve)
//       },
//       {
//         path: "/commodity",
//         name: "商品管理",
//         meta: {
//           title: "商品管理"
//         },
//         component: resolve =>
//           require(["../page/wenchuang/commodity.vue"], resolve)
//       },
//       {
//         path: "/order",
//         name: "订单管理",
//         meta: {
//           title: "订单管理"
//         },
//         component: resolve => require(["../page/wenchuang/order.vue"], resolve)
//       },
//       {
//         path: "/classification",
//         name: "分类管理",
//         meta: {
//           title: "分类管理"
//         },
//         component: resolve =>
//           require(["../page/wenchuang/classification2.vue"], resolve)
//       },
//       {
//         path: "/visitorRegistration",
//         name: "访客登记",
//         meta: {
//           title: "访客登记"
//         },
//         component: resolve =>
//           require(["../page/visitorRegistration.vue"], resolve)
//       },
//       {
//         path: "/activity",
//         name: "活动列表",
//         meta: {
//           title: "活动列表"
//         },
//         component: resolve =>
//           require(["../page/activity/activity.vue"], resolve)
//       },

//       {
//         path: "/accessStatistics",
//         name: "访问统计",
//         meta: {
//           title: "访问统计"
//         },
//         component: resolve => require(["../page/accessStatistics.vue"], resolve)
//       },
//       // 紫檀
//       {
//         path: "/memberList",
//         name: "会员列表",
//         meta: {
//           title: "会员列表"
//         },
//         component: resolve => require(["../page/member/list.vue"], resolve)
//       },
//       {
//         path: "/blackList",
//         name: "黑名单列表",
//         meta: {
//           title: "黑名单列表"
//         },
//         component: resolve => require(["../page/blacklist.vue"], resolve)
//       },
//       {
//         path: "/grayList",
//         name: "灰名单列表",
//         meta: {
//           title: "灰名单列表"
//         },
//         component: resolve => require(["../page/graylist.vue"], resolve)
//       },
//       {
//         path: "/monitor/error",
//         name: "异常日志",
//         meta: {
//           title: "异常日志"
//         },
//         component: resolve => require(["../page/monitor/error.vue"], resolve)
//       },
//       // 紫檀
//       {
//         path: "/monitor/operation",
//         name: "操作日志",
//         meta: {
//           title: "操作日志"
//         },
//         component: resolve =>
//           require(["../page/monitor/operation.vue"], resolve)
//       },
//       {
//         path: "/monitor/signIn",
//         name: "登录日志",
//         meta: {
//           title: "登录日志"
//         },
//         component: resolve => require(["../page/monitor/signIn.vue"], resolve)
//       },
//       {
//         path: "/aliPay/list",
//         name: "小程序版本列表",
//         meta: {
//           title: "小程序版本列表"
//         },
//         component: resolve => require(["../page/aliPay/list.vue"], resolve)
//       },
//       {
//         path: "/aliPay/order",
//         name: "服务市场订单",
//         meta: {
//           title: "服务市场订单"
//         },
//         component: resolve => require(["../page/aliPay/order.vue"], resolve)
//       },
//       {
//         path: "/aliPay/message",
//         name: "审核通知",
//         meta: {
//           title: "审核通知"
//         },
//         component: resolve => require(["../page/aliPay/message.vue"], resolve)
//       },
//       {
//         path: "/device",
//         name: "设备管理",
//         meta: {
//           title: "设备管理"
//         },
//         component: resolve => require(["../page/device.vue"], resolve)
//       },
//       {
//         path: "/muen",
//         name: "菜单管理",
//         meta: {
//           title: "菜单管理"
//         },
//         component: resolve => require(["../page/muen.vue"], resolve)
//       },
//       {
//         path: "/usercenter",
//         name: "用户中心",
//         meta: {
//           title: "用户中心"
//         },
//         component: resolve => require(["../page/usercenter.vue"], resolve)
//       },
//       {
//         path: "/helpdoc",
//         name: "帮助文档管理",
//         meta: {
//           title: "帮助文档管理"
//         },
//         component: resolve => require(["../page/helpdoc.vue"], resolve)
//       },
//       // 紫檀
//       {
//         path: "/appointment",
//         name: "测试数据",
//         meta: {
//           title: "测试数据"
//         },
//         component: resolve =>
//           require(["../page/appointment/appointment.vue"], resolve)
//       },
//       {
//         path: "/appointment",
//         name: "收费展览",
//         meta: {
//           title: "收费展览"
//         },
//         component: resolve =>
//           require(["../page/appointment/appointment.vue"], resolve)
//       },
//       {
//         path: "/appointment",
//         name: "展览订单",
//         meta: {
//           title: "展览订单"
//         },
//         component: resolve =>
//           require(["../page/appointment/appointment.vue"], resolve)
//       },
//       {
//         path: "/appointment",
//         name: "收费活动",
//         meta: {
//           title: "收费活动"
//         },
//         component: resolve =>
//           require(["../page/appointment/appointment.vue"], resolve)
//       },
//       {
//         path: "/appointment",
//         name: "活动订单",
//         meta: {
//           title: "活动订单"
//         },
//         component: resolve =>
//           require(["../page/appointment/appointment.vue"], resolve)
//       },
//       {
//         path: "/userList",
//         name: "用户管理",
//         meta: {
//           title: "用户管理"
//         },
//         component: resolve => require(["../page/member/userList.vue"], resolve)
//       }
//     ]
//   }
// ];

console.log(localStorage.getItem("menus"));

// let routing = '/asja'
// console.log(routing.indexOf('/'));
// console.log(routing.slice(1));
let menus = JSON.parse(localStorage.getItem("menus"));
console.log(menus);
let routes = [
  {
    path: "/",
    name: "signin",
    meta: {
      title: "重庆科技馆"
    },
    component: resolve => require(["../page/signin.vue"], resolve)
  },
  {
    path: "/warning",
    name: "404",
    meta: {
      title: "出错了"
    },
    component: resolve => require(["../page/404.vue"], resolve)
  },

  {
    path: "/main",
    name: "main",
    component: resolve => require(["../page/main.vue"], resolve),
    children: [
      {
        path: "/appointment",
        name: "测试数据",
        meta: {
          title: "测试数据"
        },
        component: resolve =>
          require(["../page/appointment/appointment.vue"], resolve)
      }
    ]
  },
  {
    path:'/searchinner/detail',
    name:'detail',
    meta:{
      title: "用户详情"
    },
    component: resolve => require(["../page/detail/detail.vue"], resolve)
  }
];
if (menus != null) {
  menus.map(item => {
    console.log(item);
    if (item.children.length != 0) {
      item.children.map(item1 => {
        if (
          item1.routing.indexOf("/") != -1 &&
          item1.routing.indexOf("/") == 0
        ) {
          item1.routing = item1.routing.slice(1);
        }
        routes[2].children.push({
          path: "/" + item1.routing,
          name: item1.menuName,
          meta: {
            title: item1.menuName
          }, 
          component: resolve =>
            require([
              `../page/${item1.routing}/${item1.routing}.vue`
            ], resolve)
        });
      });
    } else {
      if (item.routing.indexOf("/") != -1 && item.routing.indexOf("/") == 0) {
        item.routing = item.routing.slice(1);
      }
      routes[2].children.push({
        path: "/" + item.routing,
        name: item.menuName,
        meta: {
          title: item.menuName
        },
        component: resolve =>
          require([
            `../page/${item.routing}/${item.routing}.vue`
          ], resolve)
      });
    }
  });
}

// for(let i=0;i++;i<menus.length) {
//   console.log(menus[i]);

// }

console.log(routes);
// localStorage.setItem('newMenus',routes)

const router = new Router({
  mode: "hash",
  base: "/",
  routes: routes
});

router.beforeEach((to, from, next) => {
  // 手绘地图
  if (to.path == "/webview") {
    var deviceWidth = document.documentElement.clientWidth || window.innerWidth;
    if (deviceWidth >= 750) {
      deviceWidth = 750;
    }
    if (deviceWidth <= 320) {
      deviceWidth = 320;
    }
    document.documentElement.style.fontSize = deviceWidth / 7.5 + "px";
  } else {
    document.documentElement.style.fontSize = "15px";
  }

  store.commit("clearToken");

  LoadingBar.start();

  document.title =
    to.meta.title != "重庆科技馆" ? to.meta.title + " - 重庆科技馆" : to.meta.title;
  // console.log(to.matched);
  // console.log(to);
  // console.log(from);
  // console.log(routes);
  if (to.matched.length == 0) {
    next({
      name: "404",
      params: {
        path: to.name
      }
    });
  } else if (to.matched.length == 1) {
    next();
  } else {
    if (
      !store.state.token ||
      !store.state.superAdmin
      // !store.state.museumList ||
      // !store.state.museumId ||
      // !store.state.museumName ||
      // !store.state.museums
    ) {
      store.commit("storageToStore");
    }
    store.commit("routerToStore", to);
    localStorage.setItem('routerActive',to.name)
    next();
  }
});

router.afterEach((to, from) => {
  LoadingBar.finish();
});

export default router;
//获取原型对象上的push函数
const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}